package com.ruoyi.web.controller.basedata;

import com.ruoyi.basedata.domain.DmWarnStrategy;
import com.ruoyi.basedata.service.IDmWarnStrategyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 告警策略Controller
 * 
 * @author 告警策略
 * @date 2023-09-06
 */
@RestController
@RequestMapping("/basedata/strategy")
public class DmWarnStrategyController extends BaseController
{
    @Autowired
    private IDmWarnStrategyService dmWarnStrategyService;

    /**
     * 查询告警策略列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:strategy:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmWarnStrategy dmWarnStrategy)
    {
        startPage();
        List<DmWarnStrategy> list = dmWarnStrategyService.selectDmWarnStrategyList(dmWarnStrategy);
        return getDataTable(list);
    }

    /**
     * 导出告警策略列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:strategy:export')")
    @Log(title = "告警策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmWarnStrategy dmWarnStrategy)
    {
        List<DmWarnStrategy> list = dmWarnStrategyService.selectDmWarnStrategyList(dmWarnStrategy);
        ExcelUtil<DmWarnStrategy> util = new ExcelUtil<DmWarnStrategy>(DmWarnStrategy.class);
        util.exportExcel(response, list, "告警策略数据");
    }

    /**
     * 获取告警策略详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:strategy:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(dmWarnStrategyService.selectDmWarnStrategyByID(ID));
    }

    /**
     * 新增告警策略
     */
    @PreAuthorize("@ss.hasPermi('basedata:strategy:add')")
    @Log(title = "告警策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmWarnStrategy dmWarnStrategy)
    {
        return toAjax(dmWarnStrategyService.insertDmWarnStrategy(dmWarnStrategy));
    }

    /**
     * 修改告警策略
     */
    @PreAuthorize("@ss.hasPermi('basedata:strategy:edit')")
    @Log(title = "告警策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmWarnStrategy dmWarnStrategy)
    {
        return toAjax(dmWarnStrategyService.updateDmWarnStrategy(dmWarnStrategy));
    }

    /**
     * 删除告警策略
     */
    @PreAuthorize("@ss.hasPermi('basedata:strategy:remove')")
    @Log(title = "告警策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(dmWarnStrategyService.deleteDmWarnStrategyByIDs(IDs));
    }
}
